package com.sxhuayuan.parking.controller.salesman;

import com.alibaba.fastjson.JSONObject;
import com.sxhuayuan.parking.compenent.Page;
import com.sxhuayuan.parking.compenent.Pageable;
import com.sxhuayuan.parking.compenent.web.RespMessage;
import com.sxhuayuan.parking.controller.BaseController;
import com.sxhuayuan.parking.entity.Agent;
import com.sxhuayuan.parking.entity.Order;
import com.sxhuayuan.parking.entity.ParkingLotUser;
import com.sxhuayuan.parking.entity.Salesman;
import com.sxhuayuan.parking.service.OrderService;
import com.sxhuayuan.parking.service.SalesmanService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 订单
 * 
 * @author helong
 * @create 2019-08-05 9:52
 */
@RestController("salesmanOrderController")
@RequestMapping("/salesman/order")
public class OrderController extends BaseController {
	@Resource(name = "salesmanServiceImpl")
	SalesmanService salesmanService;
	@Resource(name = "orderServiceImpl")
	OrderService service;

	@PostMapping("/list")
	public RespMessage list(@RequestBody Pageable pageable) {

		Salesman current = salesmanService.getCurrent();
		if (current == null) {
			return  invalidToken();
		}
		Page<Order> page = service.findPage(pageable, current);
		return successResp(page);
	}

	@PostMapping("/statistical")
	public RespMessage statistical(@RequestBody Pageable pageable) {

		Salesman current = salesmanService.getCurrent();
		if (current == null) {
			return  invalidToken();
		}
		JSONObject obj = service.statistical(pageable, current);
		return successResp(obj);
	}
}
